"""
HumanBreakerPlayer.py

Author: Zach Epolito
Date: 9-21-08

$Id: HumanBreakerPlayer.py 325 2008-10-17 02:20:55Z malerba89 $
"""

from HumanBreakerInputFrame import HumanBreakerInputFrame
from MoveCommand import MoveCommand
from GameView import *

"""represents a human breaker
"""
class HumanBreakerPlayer:

    """Constructor."""
    def __init__(self, game, host, gui, waitTime):
        self.game = game
        self.host = host
        self.gui = gui
        self.waitTime = waitTime
        
        game.register_observer(self)
        
    """Sets a frame in the GUI to gather input
       Depreciated.
    def strategy(self, contFunctor, GUI, waitTime):
        
        #Requests the GUI to get input from the user
        if self.frame == None:
            self.frame = HumanBreakerInputFrame(GUI.getRootInputView(),
                                                contFunctor, width=300, height=100)
        #self.frame.reset()
        GUI.set_input_view(self.frame)
        self.frame = None"""

    def update(self, subject, param):
        if subject == self.game: 
            if ((param == self.game.NOTIFY_MOVE) or (param == self.game.NOTIFY_UNDO)):
                if self.game.get_last_move().get_player() == "Maker" or self.game.get_last_move() == None: 
                    frame = HumanBreakerInputFrame(self.gui.getRootInputView(),self.callback, "",
                                                      width=300, height=100)
                    self.gui.set_input_view(frame)

    def callback(self, guess):
        breakerMove = BreakerMove(guess)

        if self.game.turn == self.game.BREAKER_TURN:
            self.moveCommand.execute(breakerMove)

    def makeFirstMove(self, startFunctor):
        #self.gui.set_input_view(None)
        frame = HumanBreakerInputFrame(self.gui.getRootInputView(), self.callback, "",
                                                      width=300, height=100, )
        self.gui.set_input_view(frame)

    def setWaitTime(self, waitTime):
        self.waitTime = waitTime

    def setCommands(self, undoCommand, winCommand, moveCommand,
                    exitCommand, newGameCommand):
        self.moveCommand = moveCommand

    """handle if new game or exit command is executed"""
    def handleCommandExecuted(self, cmd):
        pass
